package com.itheima.io1.mybyteststream2;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * @author zhangbaiyan
 * @date 2024-09-20 14:58
 * @description:
 * @version:
 */
public class test5 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        /*
        Java 中的编码的方法
        public byte[] getBytes()
        public byte[] getBytes(String charsetName)

        Java中的编码的方法
        String(byte[] bytes)
        String(byte[] bytes,String charsetName)
         */
        //1.编码
        String str ="ai你哟";
        byte[] bytes1 = str.getBytes();
        System.out.println(Arrays.toString(bytes1));

        byte[] bytes2 = str.getBytes("GBK");
        System.out.println(Arrays.toString(bytes2));

        //2.解码
        String str2=new String(bytes1);
        System.out.println(str2);

        String str3=new String(bytes1,"GBK");
        System.out.println(str3);

    }
}
